package io.web.usercenter.config;

import io.web.usercenter.filter.HttpServletRequestReplacedFilter;
import org.hibernate.validator.HibernateValidator;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;

/**
 * ApplicationConfig.
 *
 * @date 2023-05-17
 */
@Configuration
public class ApplicationConfig {

    @Bean
    public Validator validator() {
        ValidatorFactory factory = Validation.byProvider(HibernateValidator.class)
                .configure()
                // fail fast = true
                .failFast(false)
                .buildValidatorFactory();
        return factory.getValidator();
    }

//    @Bean
    public FilterRegistrationBean<HttpServletRequestReplacedFilter> filterRegistrationBean() {
        FilterRegistrationBean<HttpServletRequestReplacedFilter> bean = new FilterRegistrationBean<>();
        bean.setFilter(new HttpServletRequestReplacedFilter());
        bean.addUrlPatterns("/*");
        return bean;
    }
}
